Glasgow | 26- SDC-Mar | Taras Mykytiuk | Sprint 2 | Improve_with_cache#184
Glasgow | 26- SDC-Mar | Taras Mykytiuk | Sprint 2 | Improve_with_cache#184TarasMykytiuk wants to merge 2 commits into
Conversation
|
|
||
|
|
||
| def ways_to_make_change_helper(total: int, coins: List[int]) -> int: | ||
| def ways_to_make_change_helper(total: int, coin_index: int) -> int: |
There was a problem hiding this comment.
Could also keep the coin list in the parameter so that the function can be reused on different coin list.
When we pass a list to a function, we are only passing its reference -- the cost is negligible.
The cost of evaluating len(list) is also negligible because it merely reads an attribute of the list.
|
|
||
|
|
||
| def ways_to_make_change_helper(total: int, coin_index: int) -> int: | ||
| def ways_to_make_change_helper(total: int, coin_index: int, coins: List[int], cache = {}) -> int: |
There was a problem hiding this comment.
Please note that, unlike JS, default value in Python is only created once on function definition instead of on every function call.
For fibonacci(), the cache is reusable across function calls, so setting the cache as a default parameter is acceptable.
But for ways_to_make_change_helper(), if coins is allowed to contain different coin values, then creating the cache as a default parameter would not be appropriate.
Learners, PR Template
Self checklist
Changelist
Improve with cache exercise compete.